<template>
	<view>
		<input type="text" v-model="name" @keydown.enter="SearchClass"/>
	</view>
</template>

<script>
	export default {
		name:"search",
		data() {
			return {
				name:'',
				type:''
			};
		},
		methods:{
			SearchClass(){
				// console.log(this.name)
				uni.request({
					url:'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/text_cls/garbgeClass?access_token=24.9c451242eec61d8d663a5f545cbf7987.2592000.1701152819.282335-39542891',
					method:'POST',
					data:{
						text:this.name		//name为用户输入的垃圾名称
					},
					header:{
						'Content-Type':'application/json'
					},
					fail: (err) => {
						console.log(err)
					},
					success: (res) => {
						console.log(res.data)
						uni.showModal({
							showCancel:false,
							title:"您所输入的垃圾类别为"+res.data.results[0].name
						})
					}
				})
			}
		}
	}
</script>

<style>
	input{
		 padding: 6px;
		 border: 1px solid #afafaf; 
		 border-radius: 20px;
		 width: 80%;
		 height: 80%;
		 display: block;
		 margin: auto;
	}
</style>